package com.android.adc;

import android.media.AudioManager;
import android.util.Log;

public class VolumeManager
{
	private AudioManager audioManager;
	private boolean currentVolumeUpState = false;
	
	private int highVolume = 8;
	private int lowVolume = 4;
	
	private boolean volumeAffected = false;
	
	public VolumeManager(AudioManager audioManager)
	{
		this.audioManager = audioManager;
		
		lowVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
		
	}
	
	public int getDefaultVolume() {
		return audioManager.getStreamVolume(AudioManager.STREAM_RING);
	}
	
	public void restoreVolume()
	{
		audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, lowVolume, AudioManager.FLAG_VIBRATE);
		audioManager.setStreamVolume(AudioManager.STREAM_RING, lowVolume, AudioManager.FLAG_VIBRATE);
	}
	
	public void changeVolume(boolean volumeUp)
	{
		if(volumeUp == currentVolumeUpState)
			return;
		
		//int maxValue = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		int volume = getLowVolume();
		
		if(volumeUp)
			volume = getHighVolume();
		
		/* Tylko jeżeli zaznaczona jest odpowiednia opcja zmieniaj glosnosc dzwonka */
		if(volumeAffected)
			audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_VIBRATE);
		
		audioManager.setStreamVolume(AudioManager.STREAM_RING, volume, AudioManager.FLAG_VIBRATE);
		
		Log.d("Volume", volumeUp ? "high" : "low");
		
		currentVolumeUpState = volumeUp;
	}

	public int getHighVolume() {
		return highVolume;
	}

	public void setHighVolume(int highVolume) {
		this.highVolume = highVolume;
	}

	public int getLowVolume() {
		return lowVolume;
	}

	public void setLowVolume(int lowVolume) {
		this.lowVolume = lowVolume;
	}

	public void setMusicAffected(boolean volumeAffected) 
	{
		this.volumeAffected = volumeAffected;
	}
	
	public boolean isVolumeAffected()
	{
		return this.volumeAffected;
	}

	public int getMaxVolumeValue() {
		return audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
	}
	
	public boolean isVolumeUp()
	{
		return currentVolumeUpState;
	}
}
